package com.situ.mallsdauweb.interceptor;

import com.situ.mallsdauweb.entity.Member;
import com.situ.mallsdauweb.util.RequestUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    //请求进入controller之前，拦截
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //返回 true允许进入 controller
        //false 不允许
       // Object obj=request.getSession().getAttribute("mark");
        Member m= RequestUtil.getCurrent();
        if(m != null){
            return true;
        }
        response.sendRedirect("/login");
        return false;
    }
}

